package com.thiswhyme.stream.rabbit.publish;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @description: 延时消息发送器
 * @author: thiswhyme
 * @date: 2021/1/15
 */
public abstract class AbstractDelayPublisher implements IPublisher {

    /**
     * 投递延时消息
     * @param headers 自定义消息头
     * @param delaySeconds 延时时间（秒）
     * @param msg 消息内容
     */
    public void send(Map<String, Object> headers, long delaySeconds, Object msg) {
        headers = Optional.ofNullable(headers).orElse(new HashMap<>());
        headers.put("x-delay", delaySeconds * 1000);
        defaultSend(getOutputChannel(), headers, msg);
    }
}
